{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3b75b6ba-c78f-491f-94ea-03cb54c55023",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "from PIL import Image\n",
    "\n",
    "def read_image_pixels(image_path):\n",
    "    try:\n",
    "        # 打开图片\n",
    "        image = Image.open(image_path).convert(\"RGBA\")\n",
    "        width, height = image.size\n",
    "        pixels = image.load()\n",
    "\n",
    "        for y in range(height):\n",
    "            for x in range(width):\n",
    "                # 获取像素的RGBA值\n",
    "                if y > 815 and y < 956 and x > 630 and x < 1095:\n",
    "                    r, g, b, a = image.getpixel((50, 50))\n",
    "                    r1, g1, b1, a1 = image.getpixel((, y-1))\n",
    "                    pixels[x,y] = (int((r+r1)/2),int((g+g1)/2),int((b+b1)/2),int((a+a1)/2))\n",
    "                # print(f\"Pixel at ({x}, {y}): RGBA({r}, {g}, {b}, {a})\")\n",
    "        image.save(\"./233.png\")\n",
    "    except Exception as e:\n",
    "        print(f\"An error occurred: {e}\")\n",
    "    \n",
    "# 替换为你的图片路径\n",
    "image_path = \"./125.png\"\n",
    "read_image_pixels(image_path)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d2acd7c-f3e1-4e05-9340-7c122a7c1400",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5572ad35-f10a-434b-a8e0-4575b6751610",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
